package py.owner.log.util;

import ch.qos.logback.classic.Level;
import org.apache.commons.lang3.StringUtils;
import org.slf4j.Logger;

public class LogUtil extends AbstractLogUtil {

    //监控日志
    public final static Logger MONITOR_LOGGER = org.slf4j.LoggerFactory.getLogger("ALERT_MONITOR");
    //超时日志
    public final static Logger LONG_TIME_LOGGER = org.slf4j.LoggerFactory.getLogger("LONGTIME");
    //服务日志
    public final static Logger SERVICE_LOGGER = org.slf4j.LoggerFactory.getLogger("SERVICE");
    //封装日志
    public final static Logger FACADE_LOGGER = org.slf4j.LoggerFactory.getLogger("FACADE");
    //插件日志
    public final static Logger HELPER_LOGGER = org.slf4j.LoggerFactory.getLogger("HELPER");

    public static void log(Logger logger, Level level, String message) {
        log(logger, level, message, null);
    }

    public static void log(Logger logger, Level level, String message, Throwable t) {
        if (level == null || StringUtils.isBlank(message)) {
            return;
        }
        int logLevel = level.toInt();
        switch (logLevel) {
            case Level.TRACE_INT:
                logger.trace(message, t);
                break;
            case Level.DEBUG_INT:
                logger.debug(message, t);
                break;
            case Level.INFO_INT:
                logger.info(message, t);
                break;
            case Level.WARN_INT:
                logger.warn(message, t);
                break;
            case Level.ERROR_INT:
                logger.error(message, t);
                break;
        }
    }
}
